<?php
class p_info extends Model
{
    public $info_id;
	public $info_type_id;
	public $programme_id;
	public $episode_id;
	public $onair_episode_no;
	public $video_id;
	public $chapter_id;
	public $online_time;
	public $offline_time;
	public $created_at;
	public $modified_at;
	public $title;
	public $description;
    public $extras;
	public $video_type;
	public $premium_title;
	public $premium_title_zh;
	public $premium_title_en;
	public $ppv_flag;
	public $ppv_online_time;
	public $ppv_offline_time;
	public $ppv_country_allow_list;
	public $ppv_country_deny_list;
	public $subscription_flag;
	public $subscription_free_flag;
	public $subscription_online_time;
	public $subscription_offline_time;
	public $subscription_country_allow_list;
	public $subscription_country_deny_list;

    public static function getTableName()
    {
        return 'p_info';
    }

    public function getPrimaryKey()
    {
        return array('info_id', 'info_type_id');
    }

    public function set($obj)
    {
        foreach (get_object_vars($this) as $field=>$value) {
            $this->$field = isset($obj->$field) ? $obj->$field : '';
        }
    }

    public function insert($obj)
    {
        return Model::$dbo['w']->save($obj);
    }

    public function update($obj)
    {
        return Model::$dbo['w']->save($obj);
    }

    public function delete($object)
    {
        return Model::$dbo['w']->delete(__CLASS__, "info_id=? AND info_type_id=?", array($object->info_id, $object->info_type_id));
    }

    public function findInfoNotInId(array $info_id=array(), array $info_type_id=array(), $programme_id, $episode_id)
    {
        $where = array();
        foreach ($info_id as $key=>$value) {
            $where[] = "(info_id<>{$value} OR info_type_id<>{$info_type_id[$key]})";
        }
        return Model::$dbo['r']->find(__CLASS__, "programme_id=? AND episode_id=? AND " . implode(' AND ', $where), array($programme_id, $episode_id));
    }

    public function findAllByEpisodeId($episode_id)
    {
        return self::$dbo['r']->find(__CLASS__, 'episode_id = ?', array($episode_id));
    }

}
?>
